import java.sql.*;

public class JDBCTestes {
	static String userid = "root", password = "";
	static String url = "jdbc:mysql://localhost:3306/pim";
	static Statement stmt;
	static Connection conn;

	public static Connection getConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver"); // Class.forName("myDriver.Classname")
		} catch (java.lang.ClassNotFoundException e) {
			System.err.print("ClassNotFoundException: ");
			System.err.println(e.getMessage());
		}

		try {
			conn = DriverManager.getConnection(url, userid, password);
		} catch (SQLException ex) {
			System.err.println("SQLException: " + ex.getMessage());
		}

		return conn;
	}

	public static void insertFrases(String frase) {
		Connection conn = getConnection();

		String insertString;

		// insertString = insertString.replaceAll( " de | do | da ", " " );
		String[] breakString = frase.split(" ");

		for (int i = 0; i < breakString.length; i++) {
			System.out.println(breakString[i]);

			insertString = "INSERT INTO DICIONARIO (Palavra) VALUES('"
					+ breakString[i] + "');";

			try {
				stmt = conn.createStatement();
				stmt.executeUpdate(insertString);
				stmt.close();
			} catch (SQLException ex) {
				System.err.println("SQLExeption" + ex.getMessage());
			}
		}

		try {
			conn.close();
		} catch (SQLException ex) {
			System.err.print("SQLException" + ex.getMessage());
		}
	}
}
